package com.spring.springaop.proxy;


import net.sf.cglib.proxy.Enhancer;
import org.springframework.boot.autoconfigure.sendgrid.SendGridProperties;
//import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;
//import org.springframework.cglib.proxy.Proxy;

public class Main {
    public static void main(String[] args) {
        //静态代理
//        HouseProxy proxy = new HouseProxy(new RealHouseSubject());
//        proxy.rent();
//        proxy.sale();



        //JDK动态代理
//        HouseSubject target = new RealHouseSubject();
        //运行时,创建代理对象
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class},new JDKInvocation(target));
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                target.getClass().getInterfaces(),new JDKInvocation(target));
//        proxy.sale();
//        proxy.rent();


        //CGlib动态代理
        HouseSubject target = new RealHouseSubject();
        //运行时动态创建代理对象
        HouseSubject proxy = (HouseSubject) Enhancer.create(target.getClass(),new CGlibMethodInterceptor(target));
        proxy.rent();
    }
}
